<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ page contentType="text/html;charset=utf-8"%>

<script language="JavaScript" src="<%= request.getContextPath() + "/js/popUPdesc.js" %>"></script>
<%UserVO user = (UserVO)session.getAttribute("userInfo");%>
<%@page import="com.cs.beneficios.common.ConnectionFactory,com.cs.paoyer.administration.business.model.UserVO,com.cs.beneficios.common.entity.Consultas,java.sql.SQLException,java.sql.ResultSet,java.sql.Connection, com.cs.beneficios.common.entity.database"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Consultar Subprograma</title>
    
      <script language="javascript">
            function fConsultar(){
                document.form.submit();
            } 
            
            function flimpiar(){
              document.form.subprograma.value = ""; 
              document.form.secretaria.value = ""; 
            }
           function flimpiar1(){
              document.form.subprograma.value = ""; 
              document.form.programa.value= ""; 
            }
            
             function flimpiar2(){
              document.form.programa.value = ""; 
              document.form.secretaria.value= ""; 
            }
            
            function destino(target){
              //alert(target);
              document.form.action = target;
              document.form.submit();
            }
         
    </script>
    
  </head>
  <body>
   <link href="<%= request.getContextPath() + "/css/bloques.css" %>" rel="stylesheet" type="text/css">

   <P></P>
   <P align="center"></P>
   <table cellspacing="1" cellpadding="2" border="0" width="80%" align="center">
     <tr>
       <td>
         <DIV align="center" class="titulosenblanco">ADMINISTRACI&Oacute;N&nbsp;DE&nbsp;BENEFICIOS</DIV>
       </td>
     </tr>
   </table>
   <br/>
    <DIV align="center">
    <table width="90%" border="0" cellpadding="0" cellspacing="0" align="center">
      <tr><td>
      <table width="90%" border="0" cellpadding="0" cellspacing="0" align="right">
          <tr/>
          <tr>
            <td align="center">
              <html:link page="/subprogramas/IngresarSubprograma.do?ori=consulsub">
                <img src="<%= request.getContextPath() + "/images/b_nuevo.gif" %>" alt="Nuevo" width="22" height="22" border="0"/>
                <br/>
              </html:link>
              <strong>Nuevo Beneficio</strong>
            </td>
            <td></td>
            <td></td>
            <td align="center">
              <html:link page="/subprogramas/ActivarSubprogramas.do?ori=activarsub">
                <img src="<%= request.getContextPath() + "/images/activar.gif" %>" alt="Activar" width="22" height="22" border="0"/>
                <br/>
              </html:link>
              <strong>Activar Beneficio(s)</strong>
            </td>  
            <td></td>
            <td></td>
            <!--<td align="center">
              <html:link page="/beneficios/RenovarMasiva.do">
                <img src="<%= request.getContextPath() + "/images/activar.gif" %>" alt="Renovacion Masiva" width="22" height="22" border="0"/>
                <br/>
              </html:link>
              <strong>Renovacion Masiva</strong>
            </td>-->
            <td align="center" width="25%">
                  <input type="image" src="<%= request.getContextPath() + "/images/b_nuevo.gif" %>" alt="Asignar" onclick="destino('<%=request.getContextPath() + "/Sedes/UsuarioSubprograma.do"%>')" />
                  <br/>
                  <STRONG><span>Asignar Usuarios a un Beneficio</span> </STRONG>
</td>
          </tr>
        </table>
        </td></tr>
      </table>
    <form name="form" method="GET" action="<%= request.getContextPath() + "/subprogramas/ConsultarSubprograma.do" %>">
      <table cellspacing="2" cellpadding="3" border="0" width="100%" align="center">
      <tr>
          <td width="17%" colspan="3" class="celdatabla" align="center">
            <P>Seleccione un criterio para la busqueda de beneficios</P>
          </td>
          <td width="11%"></td>
          <td></td>
        </tr>
        <tr>
          <td width="17%">&nbsp;</td>
          <td width="16%" class="celdatabla">
            <STRONG>Beneficio </STRONG></td>
           <% Object strsubprograma = request.getParameter("subprograma"); 
             if(strsubprograma == null) strsubprograma = "";
            %>
          <td width="60%">
            <input type="text" class="form" name="subprograma" value="<%=(String)strsubprograma%>" onchange="flimpiar2()" maxlength="50" size="50"/>
          </td>
          <td width="11%">&nbsp;
          </td>
          <td>&nbsp;</td>
        </tr>
<%
   
   //ConnectionFactory cf = new ConnectionFactory("beneficios","beneficios");
   ConnectionFactory cf = new ConnectionFactory();
   Consultas consulta = new Consultas(cf);
   //database db = new database();
   Connection conn = cf.getConnection();
   //Connection conn = db.getConnectionWithDriver("beneficios","beneficios");
   ResultSet rs = null;
   //UserVO user = (UserVO)session.getAttribute("userInfo");
     
   String strprograma = request.getParameter("programa");
    //rs = consulta.getNomPrograma();
    rs = consulta.getNamePrograma(user.getCode(), user.getUserGroupName(), user.getCodeArea());

    if(rs != null){%>             
        <tr>
          <td width="17%">&nbsp;</td>
          <td class="celdatabla" width="16%">
            <STRONG>Programa </STRONG></td>
          <td width="60%">
          <select name="programa" class="formLista"  onchange="flimpiar()">
          <option value="" class="form">SELECCIONE EL PROGRAMA</option>
          <%try{
            while(rs.next()){
               if(strprograma != null){
                   if(strprograma.equals(rs.getString("COD_PROGRAMA"))){%>
                   <option class="formLista" selected="selected" value="<%=rs.getString("COD_PROGRAMA")%>"><%=rs.getString("NOM_PROGRAMA")%></option>
                   <%}else{%>
                   <option class="formLista" value="<%=rs.getString("COD_PROGRAMA")%>" ><%=rs.getString("NOM_PROGRAMA")%></option>
                   <%}
               }else{%>
                 <option class="formLista" value="<%=rs.getString("COD_PROGRAMA")%>" ><%=rs.getString("NOM_PROGRAMA")%></option>
                <%}
                }%> 
             </select>
             <%}catch(SQLException e){}
             cf.closeConnection(conn);%>
          </td>
          <td width="11%">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <%}else{%>
            <tr>
            <td width="17%">Ocurrio un error</td>
            <td width="16%">&nbsp;</td>
            </tr>
          <%}
          
 String strsecretaria = request.getParameter("secretaria");
    rs = consulta.getNomSecretaria();   

    if(rs != null){%>             
        <tr>
          <td width="17%">&nbsp;</td>
          <td class="celdatabla" width="16%">
            <STRONG>Secretaria </STRONG></td>
          <td>
          <select name="secretaria" class="formLista" onchange="flimpiar1()">
          <option value="" class="form">SELECCIONE LA SECRETARIA</option>
          <%try{
             while(rs.next()){
                 if(strsecretaria != null){
                 if(strsecretaria.equals(rs.getString("codigo"))){%>
                 <option class="formLista" selected="selected" value="<%=rs.getString("codigo")%>"><%=rs.getString("nombre")%></option>
                 <%}else{%>
                 <option class="formLista" value="<%=rs.getString("codigo")%>" ><%=rs.getString("nombre")%></option>
                 <%}
                 }else{%>
                 <option class="formLista" value="<%=rs.getString("codigo")%>" ><%=rs.getString("nombre")%></option>
                <%}
                }%> 
             </select>
             <%}catch(SQLException e){}
             cf.closeConnection(conn);%>
          </td>
          <td width="11%">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <%}else{%>
            <tr>
            <td width="17%">Ocurrio un error</td>
            <td width="16%">&nbsp;</td>
            </tr>
          <%}%>
          <tr>
          <td width="17%">&nbsp;</td>
          <td width="16%"></td>
          <td width="42%"></td>
          <td width="11%">&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
          <td colspan="4">
            <DIV align="center">
              <input type="submit" value="Consultar" language="javascript" onclick="fConsultar()" alt="Click para Consultar  Subprogramas"/>
            </DIV>
          </td>
        </tr>      
        
      </table>
      
      <P>     
      <%
        if(session.getAttribute("mensajes") != null){
          out.println((String)session.getAttribute("mensajes"));
        }
          session.removeAttribute("mensajes");
        %>
       </P>
  </form> 
  </DIV>
  <table  cellspacing="3" cellpadding="2" border="0" width="90%" align="center">

    <tr>
    <td>
    <logic:notPresent scope="request" name="subprogramas">
        <DIV align="center"><%=request.getAttribute("msg")%></DIV>
    </logic:notPresent>
    <logic:present scope="request" name="subprogramas"> 
        <display:table name="requestScope.subprogramas"  requestURI='<%= request.getContextPath() + "/subprogramas/ConsultarSubprograma.do" %>' class="bordesTable" pagesize="20" id="subpro" cellpadding="3" cellspacing="1"  style="width:100%">
          <bean:define id="Subprograma" name="subpro" property="code"></bean:define>
            <display:column headerClass="headerTable" title="Beneficio" class="Numero" >
              <html:link paramId="Codigo" paramName="subpro" paramProperty="code" page="/subprogramas/ModificarSubprograma.do">
                <bean:write name="subpro" property="nombre" /> 
              </html:link> 
            </display:column>
            <display:column headerClass="headerTable" title="Sedes Asociadas" class="Numero" >
                <logic:equal name="subpro" property="tieneSede" value="N" >
                    <div align="center"><bean:write name="subpro" property="tieneSede" /></div>
                </logic:equal>
                <logic:notEqual name="subpro" property="tieneSede" value="N">
                    <html:link paramId="Codigo" paramName="subpro" paramProperty="code" page="/subprogramas/SedesAsociadas.do">
                        <div align="center"><bean:write name="subpro" property="tieneSede" /></div>
                    </html:link>
                </logic:notEqual>
            </display:column>
            <display:column headerClass="headerTable" title="Modificar" class="Numero">
              <html:link paramId="Codigo" paramName="subpro" paramProperty="code" page="/subprogramas/ModificarSubprograma.do">
                   <div align="center"><img src="<%= request.getContextPath() + "/images/modificar.gif" %>" width="16" height="16" border="0"></div>
              </html:link>       
          </display:column>	
          <bean:define id="codigo" name="subpro" property="code"></bean:define>
                <%
                  java.util.HashMap params = new java.util.HashMap();
                  params.put("codigo", codigo);
                  params.put("accion","1");
               
                  pageContext.setAttribute("parametros", params);
                %>
             <display:column headerClass="headerTable" title="Ver Usuarios" class="Numero">
              <html:link paramId="Codigo" paramName="subpro" paramProperty="code" page="/Beneficios/UsuariosxBeneficio.do">
                   <div align="center"><img src="<%= request.getContextPath() + "/images/usuario.gif" %>" width="16" height="16" border="0"></div>
              </html:link>       
          </display:column>	     
          <%--  <display:column headerClass="headerTable" title="Ver Usuarios" class="Numero">
                       <html:link name="parametros" scope="page" page="/Beneficios/UsuariosxBeneficio.do">
                             <div align="center"><img src="<%= request.getContextPath() + "/images/usuario.gif" %>" width="16" height="16" border="0"></div>
                        </html:link>       
                    </display:column>	--%>
          <display:column headerClass="headerTable" title="Ver Atributos" class="Numero">
              <html:link name="parametros" scope="page" page="/BuscarAtributo.do">
                   <div align="center"><img src="<%= request.getContextPath() + "/images/ver.gif" %>" width="16" height="16" border="0"></div>
              </html:link>       
          </display:column>	
          <display:column headerClass="headerTable" title="Desactivar" class="Numero">
              <%--<bean:define id="Subprograma" name="subpro" property="code"></bean:define>--%>
              <a onclick="return confirm('Esta seguro que desea desactivar el beneficio?')" href='javascript:vpopUsers("<%=request.getContextPath()+"/jsp/subprogramas/RazonDesactivar.jsp"%>?Codigo=<%=Subprograma%>");'>
              <div align="center"><img src="<%= request.getContextPath() + "/images/Delete.gif" %>" width="16" height="16" border="0"></div></a>      
          </display:column>	
          <display:column headerClass="headerTable" title="Eliminar" class="Numero">
              <%--<bean:define id="Subprograma" name="subpro" property="code"></bean:define>--%>
              <a onclick="return confirm('Esta seguro que desea eliminar el beneficio otorgado?')" href='javascript:vpopUsers("<%=request.getContextPath()+"/jsp/subprogramas/RazonDesactivar.jsp"%>?Codigo=<%=Subprograma%>");'>
              <div align="center"><img src="<%= request.getContextPath() + "/images/Delete.gif" %>" width="16" height="16" border="0"></div></a>      
          </display:column>	
        </display:table>
      </logic:present>
      </td>
    </tr>
  </table>
  <% cf.closeConnection(consulta.getConn());%>
  </body>
</html>
